home *** CD-ROM | disk | FTP | other *** search
- title = 'LevelEd 0.0a'
-
- import Tkinter
- import tkFileDialog
- import Pmw
- import level
- import guimaker
- import formgui
- import shelve
- import os
- import os.path
-
- from guimixin import *
-
-
- # ---------------------------------------------------------------
- # Level Editor Window Class
- #
- class LevelEditor(Pmw.PanedWidget):
- def __init__(self, parent, **kw):
- self.level = None
- optiondefs = ()
- self.defineoptions(kw, optiondefs)
- Pmw.PanedWidget.__init__(self, parent)
- self.add('left', min=100)
- self.add('right', min=100)
- self.pack(expand=1, fill='both')
- self.makeWidgets()
-
- def makeWidgets(self):
- self.widget = formgui.FormGui(self.pane('left'), self.pane('right'))
-
- def editLevel(self, level):
- self.level = level
- self.widget.setMapping(self.level)
-
- def onClose(self):
- if self.level:
- self.widget.onClose()
- self.level = None
-
- # ---------------------------------------------------------------
- # Level Editor Application Class
- #
- class EditorApp(GuiMixin, guimaker.GuiMaker):
- def start(self):
- self.serverLevelDir = "\\\\Shodan\\Project\\Justice\\Levels"
- self.level = None
-
- self.master.title("LevelEditor")
- self.master.iconname("LevelEd")
- self.master.geometry('800x600+0+0')
- self.menuBar = [
- ('File', 0,
- [guimaker.MenuItem('New...', 0, self.doSelectNewFile),
- guimaker.MenuItem('Open...', 0, self.doOpenLevel),
- guimaker.MenuItem('Quit', 0, self.quit)]
- ),
- ]
-
- self.toolBar = [
- ('Quit', self.quit, {'side': Tkinter.RIGHT}),
- ('New...', self.doSelectNewFile, {'side': Tkinter.LEFT}),
- ('Open...', self.doOpenLevel, {'side': Tkinter.LEFT}),
- ('Publish', self.doPublishLevel, {'side': Tkinter.LEFT}),
- ('Mappings...', self.notdone, {'side': Tkinter.LEFT}),
- ('Run', self.notdone, {'side': Tkinter.LEFT}),
- ('Close', self.doClose, {'side': Tkinter.LEFT}),
- ]
-
- def makeWidgets(self):
- self.levelEditor = LevelEditor(self,
- orient='horizontal',
- hull_width = 200,
- hull_height = 200)
-
- def doClose(self):
- self.levelEditor.onClose()
-
- def doImport(self):
- dlg = Pmw.MessageDialog(self, title='Select Layout File',
- defaultbutton = 0,
- message_text = 'Please select the layout level.txt file')
- dlg.iconname('Select Layout File')
- result = dlg.activate()
-
- self.importFileName = tkFileDialog.askopenfilename(
- initialdir="\\\\Shodan\Project\Justice\Art\Data\Level Layout",
- initialfile="level.txt",
- filetypes=[("FF Import Level Layout File", "*.txt")],
- defaultextension = "*.txt",
- title = "Select Level Layout File"
- )
- if self.importFileName:
- print "Importing Layout..."
- self.level.importLayout(self.importFileName)
- self.levelEditor.editLevel(self.level)
-
- def doSelectNewFile(self):
- self.fileName = tkFileDialog.asksaveasfilename(
- initialdir="C:\IGA\Jsquad\Data\Levels",
- filetypes=[("FF Level Files", "*.dat")],
- defaultextension = "*.dat",
- title = "Select New Level FileName"
- )
- if self.fileName:
- self.level = level.LevelFile(self.fileName, 1)
- self.level.initLevel()
- self.doImport()
- self.levelEditor.editLevel(self.level)
-
- def doOpenLevel(self):
- self.fileName = tkFileDialog.askopenfilename(
- initialdir="C:\IGA\Jsquad\Data\Levels",
- filetypes=[("FF Level Files", "*.dat")],
- defaultextension = "*.dat",
- )
- if self.fileName:
- self.level = level.LevelFile(self.fileName, 0)
- self.levelEditor.editLevel(self.level)
-
- def doPublishLevel(self):
- if self.level:
- cmd = "copy %s %s" % (os.path.normpath(self.fileName), os.path.normpath(self.serverLevelDir))
- print "cmd = %s" % cmd
- os.system(cmd)
- dlg = Pmw.MessageDialog(self, title='Level Published',
- defaultbutton = 0,
- message_text = 'The %s file has been published to Shodan' % self.fileName)
- dlg.iconname('Level Published')
- dlg.activate()
-
-
- # ---------------------------------------------------------------
- # TEST DRIVE
- #
- if __name__ == '__main__':
- root = Pmw.initialise()
- root.title(title)
- app = EditorApp(root)
- app.mainloop()
-